const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { VueLoaderPlugin } = require("vue-loader");

module.exports = {
  mode: "production",
  entry: "./src/main.js",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "./[name][hash:6].js",
  },

  module: {
    rules: [
      {
        test: /\.less$/i,
        use: [
          // compiles Less to CSS
          "style-loader",
          "css-loader",
          "less-loader",
        ],
      },
      {
        test: /\.vue$/,
        loader: "vue-loader",
      },
    ],
  },

  plugins: [
    new HtmlWebpackPlugin({
      // template指定html文件在哪里
      template: path.resolve(__dirname, "./src/public/index.html"),
    }),
    new VueLoaderPlugin(),
  ],

  resolve: {
    // 配置的别名
    alias: {
      "@": path.resolve(__dirname, "src/"),
    },
    // 省略的后缀
    extensions: [".js", ".json", ".wasm", ".vue"],
  },

  devServer: {
    port: 8080,
    open: true,
    // 用于做反向代理，用于解决跨域
    // 这种方案只在开发环境下生效

    // 最终项目上限的时候，需要做nginx.config.js的配置
    proxy: {
      // 用路径的第一段
      "/api": {
        // target写协议和域名
        target: "https://i.maoyan.com",
        changeOrigin: true,
      },
    },
  },
};
